package com.cat.dataStructure;
/**
 *   @description https://leetcode.cn/problems/find-indices-with-index-and-value-difference-ii/
 *   @author 曲大人的喵
 *   @create 2025/8/15 08:41
 *   @since JDK17
 */

public class Solution11 {
    public int[] findIndices(int[] nums, int id, int vd) {
        int[] ans = new int[2];
        int n = nums.length, max = 0, min = 0, t1, t2;
        for (int i = id; i < n; i++) {
            if (nums[max] < nums[i - id]) {
                max = i - id;
            }
            if (nums[min] > nums[i - id]) {
                min = i - id;
            }
            t1 = Math.abs(nums[max] - nums[i]);
            t2 = Math.abs(nums[min] - nums[i]);
            if (t1 >= vd || t2 >= vd) {
                if (t1 >= vd) {
                    ans[0] = max;
                } else {
                    ans[0] = min;
                }
                ans[1] = i;
                return ans;
            }
        }
        return new int[]{-1, -1};
    }
}
